import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _toSafeInteger from "lodash/toSafeInteger";

var _class;

/**
 * 通用导入模块
 * 由于 需要被几个页面用到, 所以需要将 model 换成 state
 * @since 2018-9-12
 * @version 0.0.1

 */
import React from 'react';
import queryString from 'query-string';
import { withRouter } from 'dva/router';
import { getCurrentOrganizationId } from 'utils/utils';
import CommonImport from "../../components/CommonImport";
var AUTO_REFRESH_DEBOUNCE = 5000;

var CommonImportRoute = withRouter(_class = /*#__PURE__*/function (_React$Component) {
  _inherits(CommonImportRoute, _React$Component);

  var _super = _createSuper(CommonImportRoute);

  function CommonImportRoute(props) {
    var _this;

    _classCallCheck(this, CommonImportRoute);

    _this = _super.call(this, props);
    var _props$location$searc = props.location.search,
        search = _props$location$searc === void 0 ? '' : _props$location$searc,
        params = props.match.params;

    var _queryString$parse = queryString.parse(search),
        _queryString$parse$sy = _queryString$parse.sync,
        sync = _queryString$parse$sy === void 0 ? false : _queryString$parse$sy,
        _queryString$parse$au = _queryString$parse.auto,
        auto = _queryString$parse$au === void 0 ? false : _queryString$parse$au,
        prefixPatch = _queryString$parse.prefixPatch,
        _queryString$parse$ar = _queryString$parse.args,
        args = _queryString$parse$ar === void 0 ? 'null' : _queryString$parse$ar,
        autoRefreshInterval = _queryString$parse.autoRefreshInterval,
        backPath = _queryString$parse.backPath,
        _queryString$parse$te = _queryString$parse.tenantId,
        tenantId = _queryString$parse$te === void 0 ? getCurrentOrganizationId() : _queryString$parse$te,
        action = _queryString$parse.action,
        key = _queryString$parse.key;

    _this.state = {
      sync: sync,
      // 是否是同步的接口
      auto: auto,
      // 是否是 同步自动的接口
      backPath: backPath || undefined,
      // 返回地址, 如果返回地址为空, 设置为 undefined
      // 兼容 两个模式, 1: 使用者指定前缀, 2: 前缀由服务端确认
      prefixPatch: prefixPatch,
      // 客户端路径前缀
      args: args,
      // 上传文件时传递的数据
      tenantId: tenantId,
      // 租户id, 是可配置的
      autoRefreshInterval: _toSafeInteger(autoRefreshInterval) || AUTO_REFRESH_DEBOUNCE,
      code: params.code,
      action: action,
      key: key
    };
    return _this;
  }

  _createClass(CommonImportRoute, [{
    key: "render",
    value: function render() {
      var _this$state = this.state,
          sync = _this$state.sync,
          auto = _this$state.auto,
          prefixPatch = _this$state.prefixPatch,
          args = _this$state.args,
          autoRefreshInterval = _this$state.autoRefreshInterval,
          backPath = _this$state.backPath,
          tenantId = _this$state.tenantId,
          code = _this$state.code,
          action = _this$state.action,
          key = _this$state.key;
      return /*#__PURE__*/React.createElement(CommonImport, {
        sync: sync,
        auto: auto,
        prefixPatch: prefixPatch,
        args: args,
        autoRefreshInterval: autoRefreshInterval,
        backPath: backPath,
        tenantId: tenantId,
        code: code,
        action: action,
        pathKey: key
      });
    }
  }]);

  return CommonImportRoute;
}(React.Component)) || _class;

export { CommonImportRoute as default };